from selenium import webdriver
from time import sleep

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

driver=webdriver.Edge()
driver.get("http://jiuxian.com")

# 全屏
driver.maximize_window()
# 点击登录
driver.find_element(By.XPATH,'/html/body/div[2]/div/div[1]/div/a[1]').click()
sleep(1)
# 输入账号密码
driver.find_element(By.ID,'userName').send_keys('18238680385')
driver.find_element(By.NAME,'_pwd').send_keys('123456Aa')
# 强等手动输入验证码
sleep(10)
# 点击登录
driver.find_element(By.XPATH,'//*[@id="save"]').click()
driver.find_element(By.ID,'bindSub').click()
sleep(3)
denglu=driver.find_element(By.CLASS_NAME,'greeting').text
print(denglu)
sleep(3)

# 登录成功之后 点击我的酒仙 关掉完善资料右上角的x 向下滚动 选择收货地址 添加收货地址 先删再加
# 回到首页 向下滚动1500 根据疯狂抢购做目标定位 agument[0] 加入购物车 断言 收藏 断言 进入收藏 断言 成功的话取消收藏 断言

# 点击我的酒仙
driver.find_element(By.XPATH,'/html/body/div[2]/div/div[2]/ul/li[1]/div[1]/a').click()
# 页面切换
driver.switch_to.window(driver.window_handles[-1])
sleep(2)
# 点x
driver.find_element(By.CLASS_NAME,'uGuideClose').click()
sleep(1)
# 滚动到底部
driver.execute_script('window.scrollTo(0,document.body.scrollHeight)')
sleep(1)
# 收货地址
driver.find_element(By.XPATH, '/html/body/div[4]/div[1]/div[2]/div[4]/a[3]').click()
sleep(3)
# 删除收货地址
driver.find_element(By.CLASS_NAME,'controlRemove').click()
sleep(2)
driver.find_element(By.XPATH,'/html/body/div[8]/div/div[3]/span[1]').click()
sleep(2)
# 断言删除成功
delete=driver.find_element(By.XPATH,'/html/body/div[8]/div/div[2]/p/span').text
print(delete)
driver.find_element(By.XPATH,'/html/body/div[8]/div/div[3]/span[1]/b').click()
sleep(3)

# 输入收货地址姓名
driver.find_element(By.ID,'people').send_keys("小小怪")
sleep(2)
# 省市区
sheng=Select(driver.find_element(By.ID,'province'))
sheng.select_by_index(1)
sleep(2)
shi=Select(driver.find_element(By.ID,'city'))
shi.select_by_value('52')
sleep(2)
qu=Select(driver.find_element(By.ID,'district'))
qu.select_by_visible_text('东城区')
sleep(2)
# 输入详细地址手机号
driver.find_element(By.ID,'address').send_keys("0034号")
driver.find_element(By.ID,'iphone').send_keys("18238680385")
sleep(2)
# 点击提交
driver.find_element(By.CLASS_NAME,'qjwSubmit2').click()
sleep(2)
# 保存成功
baocun=driver.find_element(By.CLASS_NAME,'alertContent').text
print(baocun)
driver.find_element(By.XPATH,'/html/body/div[8]/div/div[3]/span[1]').click()
sleep(2)
# 回到首页
driver.find_element(By.ID,'httpwwwjiuxiancom').click()
sleep(2)
# 向下滚动1500
driver.execute_script('window.scrollTo(0,1500)')
sleep(2)
driver.find_element(By.XPATH,'//*[@id="crazySale"]/div[1]/div[2]/div[1]/ul/li[5]/div[1]/a/img').click()
driver.switch_to.window(driver.window_handles[-1])
sleep(2)
xiangqing=driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/h1').text
print(xiangqing)
sleep(1)
price=driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[3]/div[2]/div[2]/span[1]').text
print(price)
# 加入购物车
driver.find_element(By.ID,'addToCartForDetail').click()
sleep(2)
add=driver.find_element(By.XPATH,'//*[@id="u-buy-layId"]/div/div[2]/span').text
print(add)
sleep(6)
# 点击收藏
driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[1]/div[3]/div[2]/div[1]/a/i').click()
sleep(3)
driver.find_element(By.XPATH,'/html/body/div[16]/div/div[1]/div[2]/div[1]/i').click()
sleep(1)
driver.find_element(By.XPATH,'/html/body/div[16]/div/div[1]/div[2]/div[1]/i').click()

sleep(2)
driver.switch_to.window(driver.window_handles[-1])
shoucang=driver.find_element(By.XPATH,'/html/body/div[4]/div[3]/div[2]/table/tbody/tr[2]/td[2]/div[2]/a').text
print(shoucang)
# 取消收藏
driver.find_element(By.XPATH,'/html/body/div[4]/div[3]/div[2]/table/tbody/tr[2]/td[5]/p[2]/a').click()
sleep(2)
driver.find_element(By.XPATH,'/html/body/div[8]/div/div[3]/span[1]').click()
sleep(2)

quxiao=driver.find_element(By.CLASS_NAME,'alertContent').text
print(quxiao)
driver.find_element(By.XPATH,'/html/body/div[8]/div/div[3]/span[1]').click()



sleep(5)